<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\agent\controller;

class OssConfig extends \app\AgentRest
{
    protected $model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\agent\model\OssConfig();
    }
    public function configList()
    {
        $input = $this->_input;
        $dis[] = ["uniacid", "in", $this->_uniacid_arr];
        if(!empty($input["name"])) {
            $dis[] = ["name", "like", "%" . $input["name"] . "%"];
        }
        $data = $this->model->configList($dis, $input["page_count"]);
        return $this->success($data);
    }
    public function configAdd()
    {
        $input = $this->_input;
        $input["uniacid"] = $this->_uniacid;
        \think\facade\Db::startTrans();
        $res = $this->model->configAdd($input);
        $id = $this->model->getLastInsID();
        if(!empty($id) && !empty($input["open_oss"])) {
            $path = LONGBING_EXTEND_PATH . "timg.jpg";
            if(file_exists($path)) {
                $dis["id"] = $id;
                $config = $this->model->configInfo($dis);
                $file = new \think\file\UploadedFile($path, "test.jpg");
                $file_upload_model = new \app\Common\Upload($this->_uniacid);
                $check = $file_upload_model->upload("picture", $file, $config);
                if(empty($check)) {
                    return $this->error(lang("上传配置错误,请检查上传配置是否正确"));
                }
            }
        }
        \think\facade\Db::commit();
        return $this->success($res);
    }
    public function configUpdate()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        \think\facade\Db::startTrans();
        $res = $this->model->configUpdate($dis, $input);
        if(!empty($res) && !empty($input["open_oss"])) {
            $path = LONGBING_EXTEND_PATH . "timg.jpg";
            if(file_exists($path)) {
                $config = $this->model->configInfo($dis);
                $file = new \think\file\UploadedFile($path, "test.jpg");
                $file_upload_model = new \app\Common\Upload($this->_uniacid);
                $check = $file_upload_model->upload("picture", $file, $config);
                if(empty($check)) {
                    return $this->error(lang("上传配置错误,请检查上传配置是否正确"));
                }
            }
        }
        \think\facade\Db::commit();
        return $this->success($res);
    }
    public function configInfo()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $res = $this->model->configInfo($dis);
        return $this->success($res);
    }
    public function configDel()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $res = $this->model->configDel($dis);
        if($res == 200) {
            $this->errorMsg("已有小程序使用该配置");
        }
        return $this->success($res);
    }
    public function configSelect()
    {
        $dis[] = ["uniacid", "in", $this->_uniacid_arr];
        $data = $this->model->where($dis)->order("id desc")->select();
        return $this->success($data);
    }
}

?>